//
//  BQMyCouponVC.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/5/6.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQMyCouponVC.h"
#import "BQMyCouponModel.h"
#import "BQMyCouponCell.h"
@interface BQMyCouponVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak) UITableView *couponTV;

@end
static NSString *coupon_Cell = @"coupon_Cell";
@implementation BQMyCouponVC{
    
    NSArray *_dataArray;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"优惠券";
    
    [self setupUI];
    
    [self loadData];
}

-(void)viewWillAppear:(BOOL)animated {
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
}

-(void)setupUI{
    
    UIImage *image =[UIImage imageNamed:@"v2_goback-1"];
    UIButton *btn =[[UIButton alloc]init];
    [btn  setBackgroundImage:image forState:UIControlStateNormal];
    btn.frame =CGRectMake(0, 0, 24, 24);
    
    UIBarButtonItem *button =[[UIBarButtonItem alloc]initWithCustomView:btn];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =button;
    
    

    
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"使用规则" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor lightGrayColor]];
   
    UITableView *couponTV = [[UITableView alloc]init];
    
    _couponTV = couponTV;
    
    couponTV.dataSource = self;
    
    couponTV.delegate = self;
    
    couponTV.rowHeight = 120;
    
    [self.view addSubview:couponTV];
    
    [couponTV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
 
    [couponTV registerNib:[UINib nibWithNibName:@"BQMyCouponCell" bundle:nil] forCellReuseIdentifier:coupon_Cell];
    
    couponTV.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}

-(void)click{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BQMyCouponCell *cell = [tableView dequeueReusableCellWithIdentifier:coupon_Cell forIndexPath:indexPath];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.model = _dataArray[indexPath.row];
    
    return cell;
    
}


-(void)loadData{
    
    NSDictionary *para = @{@"call" : @9};
    
    [_AccountMgr POSTWithUrlString:myCoupon_url parameters:para success:^(id responseObject) {
        
        // 获取分类模型数组
        NSArray *dictArray = responseObject[@"data"];
        
        _dataArray = [NSArray yy_modelArrayWithClass:[BQMyCouponModel class] json:dictArray];

        [self.couponTV reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
    
}
@end
